package com.gjy.redis;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-02-14 13:56:15
 */
@Configuration
public class RedisConfig {

    @Bean
    public Jedis jedis() {
        JedisPool jedisPool = new JedisPool("101.42.141.104", 6379);
        return jedisPool.getResource();
    }

    @Bean
    public RedissonClient redissonClient() {
        // 1. Create config object
        Config config = new Config();
//        config.useClusterServers().addNodeAddress("redis://101.42.141.104:6379");
        config.useSingleServer().setAddress("redis://101.42.141.104:6379");
        // Sync and Async API
        return Redisson.create(config);
        // Reactive API
        // RedissonReactiveClient redissonReactive = redisson.reactive();
        // RxJava3 API
        // RedissonRxClient redissonRx = redisson.rxJava();
    }

    public RedissonClient redissonClient2() {
        // 1. Create config object
        Config config = new Config();
//        config.useClusterServers().addNodeAddress("redis://101.42.141.104:6379");
        config.useClusterServers().addNodeAddress("redis://101.42.141.104:6379",
                "",
                "",
                "");
        // Sync and Async API
        return Redisson.create(config);
    }
}
